function selectDb(obj) {
    var id = $(obj).val();
    if (id == -1) {
        return;
    }

    $.ajax({
        type: "GET",
        url: "/dbConfig/selectDb",
        data: "id=" + id,
        success: function (rp) {
            if (rp.fail) {
                alert(rp.message);
            }
        }

    });
}


$(function ($) {

    $.ajax({
        type: "GET",
        url: "/dbConfig/list",
        success: function (rp) {
            var data = rp.data;
            // alert( "Data list: " + data );

            if (rp.fail) {
                alert(rp.message);
            }

            // 初始化数据源select 框。先清空，再添加
            $('#dsSelect').empty();
            $('#dsSelect').attr("onchange", "selectDb(this)");
            $('#dsSelect').append('<option value="-1">请选择</option>');

            for (var i = 0; i < data.length; i++) {

                var selectOption = '<option value="' + data[i].id + '">' + data[i].env + '</option>';
                if (data[i].id == rp.message) {
                    selectOption = '<option value="' + data[i].id + '" selected>' + data[i].env + '</option>';
                }
                $('#dsSelect').append(selectOption);

            }
        }
    });


});